package com.example.xyxwebbackend001.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.xyxwebbackend001.model.entity.Food;
import com.example.xyxwebbackend001.model.entity.FoodContent;
import com.example.xyxwebbackend001.model.vo.ComArtDetailsVO;
import com.example.xyxwebbackend001.model.vo.CommendListVO;
import com.example.xyxwebbackend001.model.vo.FoodListVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface FoodMapper extends BaseMapper<Food> {

    @Select("<script>" +
            "SELECT food_id as commend_id, title, city_id, cover_path FROM food " +
            "WHERE status = 1 " +
            "<if test='cityId != null'>" +
            "    AND city_id = #{cityId} " +
            "</if>" +
            "</script>")
    List<CommendListVO> getFoodListByCityId(@Param("cityId")String cityId);
    ComArtDetailsVO  selectFoodDetailsById(@Param("foodId") String foodId);

    @Select("<script>" +
            "SELECT " +
            "   f.food_id AS id," +
            "   f.title," +
            "   c.city_name AS cityName," +
            "   f.status," +
            "   DATE_FORMAT(f.create_time, '%Y-%m-%d %H:%i:%s') AS createTime " +
            "FROM food f " +
            "LEFT JOIN city c ON f.city_id = c.city_id COLLATE utf8mb4_general_ci " + // 添加COLLATE
            "WHERE f.status != 2 " +
            "<if test='keyword != null and keyword != \"\"'>" +
            "   AND f.title LIKE CONCAT('%', #{keyword}, '%')" +
            "</if> " +
            "ORDER BY f.create_time DESC" +
            "</script>")
    List<FoodListVO> getFoodList(@Param("keyword") String keyword);
}
